<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>GIANT</title>
  <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="./css/public.css" media="all">
</head>
<body>
<form class="layui-form">
          
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 商品名称</label>
				<div class="layui-input-inline">
					<input type="text" name="proName" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 商品分类</label>
				<div class="layui-input-inline">
					<!-- <input type="text" name="categories" required lay-verify="required" placeholder="请输入职业" autocomplete="off" class="layui-input"> -->
				<select id="catID" class="layui-input" name="catID"
								lay-verify="" lay-search placeholder="请选择分类">
								<option value="">请选择</option>
								<option value="2">混合道路</option>
								<option value="15">山林道路</option>
                                <option value="17">铺路道路</option>
							</select>
				</div>
			</div>		
	<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 售价</label>
				<div class="layui-input-inline">
					<input type="text" name="price" required lay-verify="required" placeholder="请输入售价" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 品牌</label>
				<div class="layui-input-inline">
					<input type="text" name="brand" required lay-verify="required" placeholder="请输入品牌" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 描述</label>
				<div class="layui-input-inline">
					<input type="text" name="description" required lay-verify="required" placeholder="请描述" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 是否包邮</label>
				<div class="layui-input-inline">
					<!-- <input type="text" name="freeShipping" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input"> -->
				<select id="freeShipping" class="layui-input" name="freeShipping"
								lay-verify="" lay-search placeholder="请选择">
								<option value="">请选择</option>
								<option value="是">是</option>
								<option value="否">否</option>
                              
							</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 销量</label>
				<div class="layui-input-inline">
					<input type="text" name="sales" required lay-verify="required" placeholder="请输入销量" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 产地</label>
				<div class="layui-input-inline">
					<input type="text" name="place" required lay-verify="required" placeholder="请输入产地" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 生产时间</label>
				<div class="layui-input-inline">
					<input type="text" name="time" required lay-verify="required" placeholder="请设置时间" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 材料</label>
				<div class="layui-input-inline">
					<input type="text" name="materials" required lay-verify="required" placeholder="请填入材料" autocomplete="off" class="layui-input">
				</div>
			</div>
  <!-- <div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;"></span> 主图</label>
				<div class="layui-input-inline">
					<input type="text" name="picture" required lay-verify="required" placeholder="上传主图" autocomplete="off" class="layui-input">
				</div>
			</div>  -->
  <div class="layui-form-item">
					<label class="layui-form-label">商品图片:</label>
					<div class="layui-input-inline" style="width:350px;">
					<button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
                  </button>
                     <img id="imgFace" style="width:120px"  src="" />
						<input type="text" id="picture" name="picture" required=""  autocomplete="off" class="layui-input">
					</div>
				</div>   
			<!-- <div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>分类id</label>
				<div class="layui-input-inline">
					<input type="text" name="catID" required lay-verify="required" placeholder="请填入材料" autocomplete="off" class="layui-input">
				</div>
			</div> -->
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 状态</label>
				<div class="layui-input-inline">
				<!-- 	<input type="text" name="startPro" required lay-verify="required" placeholder="请填入材料" autocomplete="off" class="layui-input"> -->
				<select id="startPro" class="layui-input" name="startPro"
								lay-verify="" lay-search placeholder="请选择">
								<option value="">请选择</option>
								<option value="1">上架</option>
								<option value="2">下架</option>
                              
							</select>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script src="../houtai/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script>
			//加载了layui的form模块
			layui.use(['form','upload'], function() {
				var form = layui.form;
				var $ = layui.jquery; //引入jquery
				/* var upload = layui.upload;
				
				//执行实例
				  var uploadInst = upload.render({
				    elem: '#test1' //绑定元素
				    ,url: '/wk1un9/DessigonSerclet?method=upload' //上传接口
				    ,done: function(res){
				      //上传完毕回调
				      console.log(res);
				 $("#imgUrl").val('upload/'+res.data);
				 $("#imgFace").attr('src','/wk1un9/upload/'+res.data);
				    }
				    ,error: function(){
				      //请求异常回调
				    	 
				    }
				  }); */
			  //上传图片
	                     var upload = layui.upload;
					
					//执行实例
					  var uploadInst = upload.render({
					    elem: '#test1' //绑定元素
					    ,url: '/wk1un10/ProductPhotosServlet?method=upload' //上传接口
					    ,done: function(res){
					      //上传完毕回调
					      console.log(res);
					 $("#picture").val('upload/'+res.data);
					 $("#imgFace").attr('src','/wk1un10/houtai/images/'+res.data);
					    }
					    ,error: function(){
					      //请求异常回调
					    	 
					    }
					  });  
				
				//结束
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var d = data.field; //表单中的数据，定义一个对象来接收
					//通过ajax向数据库提交数据了
					d.method="add";
					console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
					var url ='../houtai/productAdd';
					//确保数据没有问题就进行ajax提交了
					$.post(url, d,
						function(data) {
							if(data.count>0){
								console.log('添加成功');
								var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
             					 parent.layer.close(index);		//关闭窗口
							}
						}, "json");
					return false;
				});
			});
		</script>
</body>
</html>